package com.lgkj.ui.userinfo;

import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lgkj.R;
import com.lgkj.ui.BaseActivity;
import com.lgkj.utils.CommonConstant;
import com.lgkj.utils.CommonUtils;
import com.lgkj.utils.HttpUtils;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/12/5 0005.
 */

public class UserInfoByIdActivity extends BaseActivity {
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.tv_city)
    TextView tvCity;
    @BindView(R.id.tv_shop_name)
    TextView tvShopName;
    @BindView(R.id.tv_shop_adress)
    TextView tvShopAdress;
    @BindView(R.id.ll_item)
    LinearLayout llItem;
    private String user_id = "";
    private String user_level="0";
    @Override
    public int getLayoutId() {
        return R.layout.activity_user_info_by_id;
    }

    @Override
    public void initView() {
        setTitle("用户信息");
        user_id = getIntent().getStringExtra("user_id");
        if (user_id == null) {
            return;
        }
        user_level=getIntent().getStringExtra("user_level");
        Log.i(TAG, "initView: "+user_level );
        if(user_level.equals("3")){
            llItem.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void initData() {
        CommonUtils.showDiaLog(UserInfoByIdActivity.this, "正在查询中");
        Map<String, String> map = new HashMap<>();
        map.put("access_token", getToken());
        map.put("uid", user_id);
        HttpUtils.postHttp(map, CommonConstant.getTeamUserInfo, new HttpUtils.HttpCallBack() {
            @Override
            public void successHttp(JSONObject jsonObject, int id) {
                if (jsonObject.optInt("code") == 0) {
                    JSONObject object=jsonObject.optJSONObject("data");
                    tvName.setText("姓名: "+object.optString("name"));
                    tvPhone.setText("电话: "+object.optString("phone"));
                    tvCity.setText("城市: "+object.optString("city_name"));
                    tvShopName.setText("店铺名称: "+object.optString("barbershop_name"));
                    tvShopAdress.setText("店铺地址: "+object.optString("barbershop_address"));
                }
            }

            @Override
            public void errorHttp(String msg) {

            }
        });
    }
}
